package mine.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.whu.administrator.ws.MyApplication;
import com.whu.administrator.ws.R;

import java.util.ArrayList;
import java.util.List;

import main.network.Login;

/**
 * 工作地点
 * Created by Administrator on 2016/2/29.
 */
public class WorkSpaceAdapter extends BaseAdapter {

    List<Login.WorkLocInfo> workLocInfos = new ArrayList<Login.WorkLocInfo>();

    public void setWorkLocInfos(List<Login.WorkLocInfo> workLocInfos) {
        this.workLocInfos = workLocInfos;
    }

    @Override
    public int getCount() {
        return workLocInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return workLocInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView = View.inflate(MyApplication.share(), R.layout.item_workspace,null);
            viewHolder.setTv_name((TextView) convertView.findViewById(R.id.id_tv_locName));
            viewHolder.setLatitude((TextView) convertView.findViewById(R.id.id_tv_latitude));
            viewHolder.setLongtitude((TextView) convertView.findViewById(R.id.id_tv_longtitude));
            convertView.setTag(viewHolder);
        }
        else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        Login.WorkLocInfo workLocInfo = workLocInfos.get(position);
        viewHolder.getTv_name().setText(workLocInfo.getWorkLoc_Name());
        viewHolder.getLongtitude().setText(workLocInfo.getLongitude());
        viewHolder.getLatitude().setText(workLocInfo.getLatitude());
        return convertView;
    }

    public static class ViewHolder
    {
        TextView tv_name;
        TextView longtitude;
        TextView latitude;

        public TextView getTv_name() {
            return tv_name;
        }

        public void setTv_name(TextView tv_name) {
            this.tv_name = tv_name;
        }

        public TextView getLongtitude() {
            return longtitude;
        }

        public void setLongtitude(TextView longtitude) {
            this.longtitude = longtitude;
        }

        public TextView getLatitude() {
            return latitude;
        }

        public void setLatitude(TextView latitude) {
            this.latitude = latitude;
        }
    }
}
